package sparrowGui.components
{
	import flash.display.DisplayObject;
	
	import sparrowGui.components.item.ItemFactory;
	import sparrowGui.components.item.SItem;
	import sparrowGui.components.item.SListItem;
	import sparrowGui.i.IItemFactory;
	
	/**
	 * 多选控件
	 * 
	 * 例子如下
	 * 
		var cb:SCheckBox = new SCheckBox();
		cb.update([11,22,33,44,55,66]);
		addChild(cb);
	 * 
	 * @author Pelephone
	 * @website http://cnblogs.com/pelephone
	 */
	public class SCheckBox extends SRadioGroup
	{
		/**
		 * 多选组件控件
		 * @param argSkin
		 * @param vars
		 */
		public function SCheckBox(uiVars:Object=null,cellFactory:IItemFactory=null)
		{
			cellFactory = cellFactory || new ItemFactory(SListItem,"checkItem");
			super(uiVars,cellFactory);
			selectData.multiSelect = true;
		}
		
		/**
		 * 获取选中项index
		 * @return 
		 */
		public function getSelectIds():Vector.<int>
		{
			return selectData.getSelectIds();
		}
		
		/**
		 * 获取选中项
		 * @return 
		 */
		public function getSelectItems():Vector.<SItem>
		{
			var resLs:Vector.<SItem> = new Vector.<SItem>();
			for (var i:int = 0; i < itemLs.length; i++) 
			{
				if(selectData.isSelect(i))
					resLs.push(itemLs[i]);
			}
			return resLs;
		}
		
		/**
		 * 反选所有项
		 */
		public function invertSelect():void
		{
			selectData.invertSelect(itemLs.length);
		}
		
		override public function getDefaultUIName():String
		{
			return "checkBox";
		}
		
		/**
		 * 添加单选事件
		 
		override public function addListener():void
		{
//			for each (var itm:RichItem in itemTarget) 
//			{
//				itm.addEventListener(ItemEvent.ITEM_SELECT_CHANGE,onItemSelectEvt);
//			}
		}*/
		
		/**
		 * 移出项事件
		 
		override public function removeListener():void
		{
//			for each (var itm:RichItem in itemTarget) 
//			{
//				itm.skin.removeEventListener(MouseEvent.CLICK,onItemSelectEvt);
//			}
		}*/
		
/*		override public function create(itemBtns:Array=null):void
		{
			itemLink = [];
			super.create(itemBtns);
		}*/
		
		/**
		 * 从缓存链表中生成item
		 * @return 
		 
		override protected function createItem(itmSkin:Sprite=null):RichItem
		{
			var itm:RichItem = new itemClass();
			itm.reset(itmSkin);
			return itm;
		}*/
		
		/**
		 * 设置项
		 
		override protected function setItemAt(itemName:String,itm:RichItem):void
		{
			super.setItemAt(itemName,itm);
			itemLink.push(itemName);
		}*/
		
		/**
		 * 获取第一个选中项名
		 * @return 
		 
		override public function get selectItemName():String
		{
			for each(var itm:RichItem in itemTarget)
				if(itm.selected) return itm.name;
				
			return null;
		}*/
		
		/**
		 * 获取所有选中项的名数组
		 * @return 
		 
		public function getSelectItemNames():Array
		{
			var arr:Array = [];
			for each(var itm:RichItem in itemTarget)
			{
				if(itm.selected) 
					arr.push(itm.name);
			}
			return arr;
		}*/
		
		/**
		 * 获取所有选中的项数组
		 * @return 
		 
		public function getSelectItems():Array
		{
			var arr:Array = [];
			for each(var itm:RichItem in itemTarget)
			{
				if(itm.selected) 
					arr.push(itm);
			}
			return arr;
		}*/
	}
}